package com.canaan.business.controller.pc.quality;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.enums.BusinessType;
import javax.annotation.Resource;
import com.canaan.business.domain.quality.ProductQualityTaskDetail;
import com.canaan.business.service.quality.IProductQualityTaskDetailService;
import com.canaan.common.utils.poi.ExcelUtil;
import com.canaan.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 物料质检任务明细Controller
 *
 * @author ruoyi
 * @date 2023-02-07
 */
@Api(tags = "物料质检任务明细")
@RestController
@RequestMapping("/quality/qualityTaskDetail")
public class ProductQualityTaskDetailController extends BaseController {
    @Resource
    private IProductQualityTaskDetailService productQualityTaskDetailService;

    /**
     * 查询物料质检任务明细列表
     */
    @ApiOperation(value = "查询物料质检任务明细列表")
    @GetMapping("/list")
    public TableDataInfo list(ProductQualityTaskDetail productQualityTaskDetail) {
        startPage();
        List<ProductQualityTaskDetail> list = productQualityTaskDetailService.selectProductQualityTaskDetailList(productQualityTaskDetail);
        return getDataTable(list);
    }

    /**
     * 导出物料质检任务明细列表
     */
    @ApiOperation(value = "导出物料质检任务明细列表")
    @Log(title = "物料质检任务明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductQualityTaskDetail productQualityTaskDetail) {
        List<ProductQualityTaskDetail> list = productQualityTaskDetailService.selectProductQualityTaskDetailList(productQualityTaskDetail);
        ExcelUtil<ProductQualityTaskDetail> util = new ExcelUtil<ProductQualityTaskDetail>(ProductQualityTaskDetail.class);
        util.exportExcel(response, list, "物料质检任务明细数据");
    }

    /**
     * 获取物料质检任务明细详细信息
     */
    @ApiOperation(value = "获取物料质检任务明细详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(productQualityTaskDetailService.selectProductQualityTaskDetailById(id));
    }

    /**
     * 新增物料质检任务明细
     */
    @ApiOperation(value = "新增物料质检任务明细")
    @Log(title = "物料质检任务明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductQualityTaskDetail productQualityTaskDetail) {
        return toAjax(productQualityTaskDetailService.insertProductQualityTaskDetail(productQualityTaskDetail));
    }

    /**
     * 批量新增物料质检任务明细
     */
    @ApiOperation(value = "批量新增物料质检任务明细")
    @Log(title = "批量新增物料质检任务明细", businessType = BusinessType.INSERT)
    @PostMapping("/batchSave")
    public AjaxResult add(@RequestBody List<ProductQualityTaskDetail> productQualityTaskDetailList) {
        return toAjax(productQualityTaskDetailService.batchInsertProductQualityTaskDetail(productQualityTaskDetailList));
    }

    /**
     * 修改物料质检任务明细
     */
    @ApiOperation(value = "修改物料质检任务明细")
    @Log(title = "物料质检任务明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductQualityTaskDetail productQualityTaskDetail) {
        return toAjax(productQualityTaskDetailService.updateProductQualityTaskDetail(productQualityTaskDetail));
    }

    /**
     * 删除物料质检任务明细
     */
    @ApiOperation(value = "删除物料质检任务明细")
    @Log(title = "物料质检任务明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(productQualityTaskDetailService.deleteProductQualityTaskDetailByIds(ids));
    }


    @ApiOperation(value = "质检项导入")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file,String taskNo) throws Exception {
        ExcelUtil<ProductQualityTaskDetail> util = new ExcelUtil<>(ProductQualityTaskDetail.class);
        List<ProductQualityTaskDetail> fileDataList = util.importExcel(file.getInputStream());
        String message = this.productQualityTaskDetailService.importData(fileDataList,taskNo);
        return success(message);
    }
}
